<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" placeholder="请输入第一个数" id="nu1"><br>
<input type="text" placeholder="请输入第二个数" id="nu2"><br>
<button onclick="calc('+')">加</button>
<button onclick="calc('-')">减</button>
<button onclick="calc('*')">乘</button>
<button onclick="calc('/')">除</button>
<h4>运算结果:<span></span></h4>

<script>
    function calc(op){
        let n1 = document.querySelector('#nu1').value;
        let n2 = document.querySelector('#nu2').value;
        n1 = parseFloat(n1);
        n2 = parseFloat(n2);
        let spanE = document.querySelector('span');
        switch (op){
            case '+':
                spanE.innerHTML = n1+n2;
                break;
            case '-':
                spanE.innerHTML = n1-n2;
                break;
            case '*':
                spanE.innerHTML = n1*n2;
                break;
            case '/':
                if(n2 !=0){
                    spanE.innerHTML = n1/n2;
                }
                else{
                   alert('除数不能为0');
                }

        }
    }
</script>
</body>
</html>